Repository navigation
refactor!: redesign Error without anyhow dependency - #248
Merged
Merged
Conversation
`logforth-core` previously depended on `anyhow` solely for `Error::with_source`, coupling `logforth-core`'s public error signature to `anyhow` while returning an unboxed 56-byte `Error` struct across hot `Visitor::visit`, `Layout::format`, and `Append::append` paths. Box the internal error state (`ErrorState`) into a pointer-sized payload carrying a `Cow<'static, str>` message and an optional `Box<dyn std::error::Error + Send + Sync + 'static>` cause: - Remove the mandatory `anyhow` dependency from `logforth-core` while preserving `Into` conversions for standard errors, strings, and boxed causes. - Shrink `Result<(), Error>` to a single word on the stack, expose `Error::message()`, walk the full `.source()` chain in `Debug`, and allow `with_source` to replace an existing cause without panicking. - Remove `with_context`, `sources`, `from_io_error`, and `from_fmt_error`, replacing generic I/O wrappers with descriptive operation messages at each appender call site. Signed-off-by: tison <wander4096@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
logforth-corepreviously depended onanyhowsolely forError::with_source, couplinglogforth-core's public API toanyhowwhile returning an unboxed 56-byteErrorstruct across hotVisitor::visit,Layout::format, andAppend::appendreturn paths.This change boxes the internal error representation (
ErrorState) into a pointer-sized payload carrying aCow<'static, str>message and an optionalBox<dyn std::error::Error + Send + Sync + 'static>cause, aligninglogforth_core::ErrorwithDESIGN.md:anyhowdependency fromCargo.tomlandlogforth-core, leavinglogforth-corewith zero mandatory third-party dependencies.ErrorandResult<(), Error>to a single machine word (8bytes on 64-bit targets).Error::message(), walk the full.source()chain inDebugoutput, and allowError::with_sourceto replace an existing cause without panicking.with_context,sources,from_io_error, andfrom_fmt_error, replacing generic"failed to perform io"wrappers with operation-specific messages at each appender call site.